package com.itheima.features.catc;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class TryCatchDemo01 {

    public static void main(String[] args) {

        /**
         * 演示：IO流中针对异常的处理
         */
        FileInputStream fileInputStream = null ;
        FileOutputStream fileOutputStream = null ;
        try {

            fileInputStream = new FileInputStream("") ;
            fileOutputStream = new FileOutputStream("") ;

            // 一次取读取一个字节数组进行文件的复制
            byte[] bytes = new byte[1024] ;
            int len = -1 ;
            while((len = fileInputStream.read(bytes)) != -1) {
                fileOutputStream.write(bytes , 0 , len);
            }

        }catch (Exception e) {
            e.printStackTrace();
        } finally {

            // 进行资源的释放
            if(fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

    }

}
